package vn.kiemviec.app.fragments;

import vn.kiemviec.app.R;
import vn.kiemviec.app.data.JobEntry;
import vn.kiemviec.app.task.CBGetDetailsTask.CBDetailsTaskListener;
import vn.kiemviec.app.task.GetJobDetailsTask;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class JobDetailsFragment extends BaseFragment{

	private Button btnBack;
	private Button btnSearchAgain;
	private Button btnApply;
	private Button btnSave;
	private Button btnSimilarJob;
	private Button btnShare;
	
	private TextView txvJobTitle;
	private TextView txvCompany;
	private TextView txvLocation;
	private TextView txtIndustry;
	private TextView txvDescription;
	
	private TextView txvContactName;
	private TextView txvContactCompany;
	private TextView txvContactAddress;
	private TextView txvContactCountry;
	
	private String mJobID;
	public static  JobDetailsFragment newInstance(String id){
		JobDetailsFragment fr = new JobDetailsFragment();
		fr.setJobId(id);
		return fr;
	}
	
	public void setJobId(String id){
		mJobID = id;
	}
	
	@Override
	public int OnGetLayoutResID() {
		// TODO Auto-generated method stub
		return R.layout.frag_jobdetails;
	}
	
	@Override
	public void onSetUpView() {
		// TODO Auto-generated method stub
		btnBack			= findView(R.id.btnLogin);
		btnSearchAgain	= findView(R.id.btnSearchAgain);
		
		txvJobTitle		= findView(R.id.txvJobTitle);
		txvCompany		= findView(R.id.txvJobCompany);
		txvLocation		= findView(R.id.txvLocation);
		
		txvDescription	= findView(R.id.txvDescripton);
		
		loadData();
	}

	@Override
	public void onSetUpEventHandler() {
		// TODO Auto-generated method stub
		btnBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				NavParrent.popFragment();
			}
		});
		btnSearchAgain.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
	}
	
	private void loadData(){
		GetJobDetailsTask task = new GetJobDetailsTask(getActivity(), mJobID);
		task.setOnTaskListener(new CBDetailsTaskListener<JobEntry>() {

			@Override
			public void onSuccessfull(JobEntry entry) {
				// TODO Auto-generated method stub
				txvJobTitle.setText(entry.Title);
				txvCompany.setText(entry.Company);
				txvDescription.setText(Html.fromHtml(entry.Description));
				
			}

			@Override
			public void onError(int error) {
				// TODO Auto-generated method stub
				
			}
		});
			
		task.execute();
	}

}
